package cn.com.pansky.comm.interceptor;

import java.util.HashSet;
import java.util.Set;

import javax.servlet.ServletContext;

import net.vsame.url2sql.helper.Url2SqlContext;
import net.vsame.url2sql.helper.WebHelper;
import net.vsame.url2sql.sql.Model;
import net.vsame.url2sql.url.Interceptor;
import net.vsame.url2sql.url.impl.UrlMapping;
import net.vsame.url2sql.url.impl.UrlMapping.Chain;
import cn.com.pansky.service.CertificationService;

public class BusinessInterceptor implements Interceptor {

	private static Set<String> set = new HashSet<String>(); 

	static {
		
		set.add("/myAccount/refreshFace/friendList");
		set.add("/myAccount/phoneNum/updPhoneNum");
		set.add("/person/contact/list");
	}
	
	@Override
	public void init(UrlMapping urlMapping, ServletContext servletContext) {
	}

	@Override
	public void invoke(Chain chain) {
		Url2SqlContext context = WebHelper.getContext();
		if(!set.contains(context.getRequestUrl())){
			chain.next();
			return ;
		}
		try {
			
			CertificationService cs = new CertificationService();
			Model m = (Model) context.getServletSession().getAttribute("user");
			String userid = m.getString("AA001");
			if(cs.isCertification(userid)) {
				chain.next();
				return ;
			}
			context.putError(201, "用户未完成实名认证");
		} catch (Exception e) {
			context.putError(1, "登陆超时，请重新登陆!");
		}
	}

	@Override
	public void destroy() {
	}
	

}
